//
//  YZSickerMessageViewController.m
//  患者信息界面（代码）
//
//  Created by Yip-Jun on 16/5/9.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZSickerMessageViewController.h"
#import "YZSickerMessageScrollView.h"
#import "Masonry.h"
#import "YZManagerViewController.h"
#import "YZSickMessageCoverView.h"
#import "YZDoctorModel.h"

@interface YZSickerMessageViewController ()

@property (nonatomic, strong) YZSickerMessageScrollView *scrollView;

@property (nonatomic, strong) UIButton *correctButton;

@property (nonatomic, strong) YZSickMessageCoverView *coverView;

@property (nonatomic, strong) YZDoctorModel *doctorMoedl;

@end

@implementation YZSickerMessageViewController

+ (instancetype)sickerMessageViewController:(YZDoctorModel *)doctorModel {
    YZSickerMessageViewController *vc = [[YZSickerMessageViewController alloc] init];
    
    vc.doctorMoedl = doctorModel;
    
    return vc;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
//    self.automaticallyAdjustsScrollViewInsets = NO;
    
    self.view.backgroundColor = [UIColor blackColor];

    [self prepareUI];
    [self layoutSubviewsContraint];

}

- (void)prepareUI {
    
    [self.view addSubview:self.scrollView];
    [self.view addSubview:self.correctButton];
}

- (void)layoutSubviewsContraint {
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    [self.correctButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom);
        make.centerX.equalTo(self.view);
        CGFloat width = [UIScreen mainScreen].bounds.size.width * 0.8;
        make.width.mas_equalTo(width);
        make.height.mas_equalTo(width * 0.12);
    }];
}

- (void)correctButtonDidClick:(UIButton *)button {
    
    [self prepareCoverView];
    [self setCoverViewFrame];
}

- (void)prepareCoverView {
    [self.view addSubview:self.coverView];
}

- (void)setCoverViewFrame {
    [self.coverView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
}

- (YZSickerMessageScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [YZSickerMessageScrollView sickerMessageScrollView];
        _scrollView.backgroundColor = [UIColor whiteColor];
        __weak __typeof(self)weakSelf = self;
        _scrollView.changeButtonOfSickViewBeDidClickBlock = ^ {
            [weakSelf.navigationController pushViewController:[[YZManagerViewController alloc] init] animated:YES];
        };
    }
    return _scrollView;
}

- (UIButton *)correctButton {
    if (!_correctButton) {
        _correctButton = [[UIButton alloc] init];
        _correctButton.backgroundColor = [UIColor colorWithRed:86 / 255.0 green:141 / 255.0 blue:255 / 255.0 alpha:1];
        [_correctButton addTarget:self action:@selector(correctButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
        [_correctButton setTitle:@"确定" forState:UIControlStateNormal];
        [_correctButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    return _correctButton;
}

- (YZSickMessageCoverView *)coverView {
    if (!_coverView) {
        _coverView = [YZSickMessageCoverView sickMessageCoverView:self.doctorMoedl];
        _coverView.doctorModel = self.doctorMoedl;
        __weak __typeof(self)weakSelf = self;
        _coverView.reservationViewCannelButtonDidClickBlock = ^ {
            [weakSelf.coverView removeFromSuperview];
            weakSelf.coverView = nil;
        };
    }
    return _coverView;
}

@end
